package com.rjkj.medicalwaste.adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.rjkj.medicalwaste.R
import com.rjkj.medicalwaste.bean.TestBean
import com.rjkj.medicalwaste.bean.UserBean
import com.rjkj.medicalwaste.databinding.ItemSimpleStringBinding

class UserListAdapter: PagingDataAdapter<UserBean, UserListAdapter.ViewHolder>(COMPARATOR) {
    companion object {
        private val COMPARATOR = object : DiffUtil.ItemCallback<UserBean>() {
            override fun areItemsTheSame(oldItem: UserBean, newItem: UserBean): Boolean {
                return oldItem.name == newItem.name
            }

            override fun areContentsTheSame(oldItem: UserBean, newItem: UserBean): Boolean {
                return oldItem == newItem
            }
        }
    }


    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        getItem(position)?.let { holder.bind(it) }
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = ItemSimpleStringBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(view)
    }
    class ViewHolder(private val binding:ItemSimpleStringBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(item:UserBean){
            binding.apply {
                this.user = item
                executePendingBindings()
            }
        }
    }
}